# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lua-b64
pkgver=0.1
pkgrel=5
pkgdesc="Lua base64 implementation with support for urlsafe"
url="https://github.com/ncopa/lua-b64"
arch="all"
license="MIT"
depends="lua"
source="$pkgname-$pkgver.tar.gz::https://github.com/ncopa/lua-b64/archive/v$pkgver.tar.gz
	0001-b64-fix-segfault-caused-by-signed-char.patch"
options="!check"

_luaversions="5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

prepare() {
	default_prepare

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver"
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."
		make -C "$builddir-$lver" LUAPC=lua$lver
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local cmod_dir="$subpkgdir/$(pkg-config --variable=INSTALL_CMOD lua$lver)"

	install -D -m 755 "$builddir-$lver"/b64.so "$cmod_dir"/b64.so
}

sha512sums="8740d5061db01dca166ce2c959548a3232c85dce156fce3502da35f457db79db2bf23242ee6d26b64f4141c451db733898328b8fc3d1f62b47e8f7ec790577d1  lua-b64-0.1.tar.gz
6da3b8048b2e6772a4aac954ea2db35f9c21897d720e7ff9dc6c1d63ffc37eeb4fb91be46bc13b32a2c3d1b88997172fe259ea699ac8591f0f3e1fd53cae378b  0001-b64-fix-segfault-caused-by-signed-char.patch"
